﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
namespace ITXHWEB.Controllers
{
    public partial class KDSTAMMController : ITXController
    {
        public KDSTAMMController()
        {

        }
        [ChildActionOnly]
        public ActionResult SKD(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            KDSTAMMModel m = new KDSTAMMModel();
            m.TERMNO = app.TERMNO;
            return PartialView(m);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SKD(KDSTAMMModel model, string returnUrl)
        {
            try
            {
                ModelState.Clear();
                KDKUNDNA = model.KDKUNDNA.Trim();
                NEWVKK(model);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP);
        }
        public void NEWVKK(KDSTAMMModel model)
        {
            VKPS = null;
            IsVKKReady = false;
            if (KDKUNDNA.Trim().Length < 2)
            {
                IsVKKReady = false;
            }
            else
            {
                IsVKKReady = true;
            }
            VPOS = 0;
            MORDER = VHP.MRD.GETORD();
            PM["dwInput"] = null;
            PM["KRS"] = "EX";
            PM["LFD"] = Helper.Right("000000" + MORDER, 6);
            VPOS++;
            PM["POS"] = Helper.Right("000" + VPOS, 3);
            PM["CUSTOMER"] = KDKUNDNA.PadRight(40);
            PM["CUSER"] = app.User;
            PM["USD2RMB"] = VHP.MRD.USD2RMB;
            PM["RATE1"] = VHP.MRD.RATE1;
            dwVKP = VHP.EXORD.NEWVKP(PM); 
        }
    }
}
